package study.concurrent.thread.service;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import study.concurrent.thread.support.session.UserContext;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class UserService {

    private ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 10,
            0, TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<>(10),
            new ThreadFactoryBuilder().setNameFormat("UserInfo-Test-222222-%s").build());

    public void getUserInfo() {
        pool.submit(() -> {
            log.info(">>>>>> {}", UserContext.get());
        });
    }
}
